package routers

import (
	"github.com/gin-gonic/gin"
	"learningProject/vueGoProject/Controller"
	"learningProject/vueGoProject/middleware"
)

// 用户注册
func CollectRouter(r *gin.Engine) *gin.Engine {
	r.Use(middleware.CorsMiddleware(), middleware.RecoveryMiddleWare())
	r.POST("/api/auth/register", Controller.Register)
	r.POST("/api/auth/login", Controller.Login)
	// 查看用户信息接口必须要token,用jwt保护
	r.GET("/api/auth/info", middleware.AuthMiddleWare(), Controller.Info)

	categoryRouters := r.Group("/categories")
	categoryController := Controller.NewCategoryController()
	categoryRouters.POST("", categoryController.Create)       // 创建
	categoryRouters.PUT("/:id", categoryController.Update)    // 更新
	categoryRouters.GET("/:id", categoryController.Show)      // 获取
	categoryRouters.DELETE("/:id", categoryController.Delete) // 删除

	postRouters := r.Group("/posts")
	postRouters.Use(middleware.AuthMiddleWare()) // 给路由组增加的中间件
	postController := Controller.NewPostController()
	postRouters.POST("", postController.Create)             // 创建
	postRouters.PUT("/:id", postController.Update)          // 更新
	postRouters.GET("/:id", postController.Show)            // 获取
	postRouters.DELETE("/:id", postController.Delete)       // 删除
	postRouters.POST("/page/list", postController.PageList) // 分页

	return r
}

// 用户登录
